import 'dart:math';

import 'package:flutter/material.dart';

class MySliverTabBarDelegate extends SliverPersistentHeaderDelegate {
  final TabBar child;
  final double minHeight; // 最大高度
  final double maxHeight; // 最小高度

  MySliverTabBarDelegate({
    required this.child,
    required this.minHeight, // 最大高度
    required this.maxHeight,
  });

  @override
  double get maxExtent => max(maxHeight, minHeight);

  @override
  double get minExtent => minHeight;

  @override
  Widget build(BuildContext context, double shrinkOffset, bool overlapsContent) {
    // return child;
    // return SizedBox.expand(child: child);
    return SizedBox.expand(
      child: Container(
        decoration: const BoxDecoration(color: Colors.white),
        child: child,
      ),
    );
  }

  @override
  bool shouldRebuild(covariant SliverPersistentHeaderDelegate oldDelegate) {
    // return true;
    return false;
  }
}
